#include "spinlock.h"

void init_lock(struct spinlock *lk, char *name)
{
	lk->name = name;
	lk->locked = 0;
}

void acquire_lock(struct spinlock *lk)
{
	// On RISC-V, sync_lock_test_and_set turns into an atomic swap
	while(__sync_lock_test_and_set(&lk->locked, 1) != 0);

}

void release_lock(struct spinlock *lk)
{
	__sync_lock_release(&lk->locked);
}
